/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Data;

import java.sql.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author Adrian
 */
public class coneccion
{

    private Connection conexion;

    private void abrirconeccion()
    {
        try {
            Class.forName("com.mysql.jdbc.Driver");
            try {
                conexion = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/bd_kinesiologia","root","123456");
                System.out.print("Coneccion exitosa\n");
            } catch (SQLException ex) {
                Logger.getLogger(coneccion.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(coneccion.class.getName()).log(Level.SEVERE, null, ex);
        }
            

    }

   public ResultSet hacerConsultaSelect(String consulta)
    {
       this.abrirconeccion();
       ResultSet tabla=null;
        try {
            Statement stmt;
            stmt = (Statement) conexion.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
				     ResultSet.CONCUR_UPDATABLE);
            tabla = stmt.executeQuery(consulta);


        } catch (SQLException ex) {
            Logger.getLogger(coneccion.class.getName()).log(Level.SEVERE, null, ex);
        }
     return tabla;

    }

   public void hacerConsultas(String consulta)
    {

        try {
            Statement stmt;
            stmt = (Statement) conexion.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
				     ResultSet.CONCUR_UPDATABLE);
            stmt.execute(consulta);
            this.cerrarConeccion();
        } catch (SQLException ex) {
            Logger.getLogger(coneccion.class.getName()).log(Level.SEVERE, null, ex);
        }


    }

   public void cerrarConeccion()
    {
        try {
            conexion.close();
             System.out.print("Coneccion cerrada\n");
        } catch (SQLException ex) {
            Logger.getLogger(coneccion.class.getName()).log(Level.SEVERE, null, ex);
        }
   }

}
